<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<jsp:include page="/pages/sysIndex/default.jsp"/>
<style>
    .deleteImg {
        width: 20px;
        position: relative;
        top: 0px;
        left: 20px;
        cursor: pointer;
        display: none;
    }

    .startImg {
        width: 131px;
        height: 32px;
    }
    .icheckbox_minimal-grey {
        background: white;
    }
</style>
<div class="main-content">
    <div class="box box-main">
        <form id="maintainDataForm" model="post" enctype="multipart/form-data" action="<c:url value="/web/admin/maintainData/executeEdit.action"/>" method="post" class="form-horizontal">
            <div class="box-footer">
                <div class="row">
                    <div class="col-sm-offset-2 col-sm-12">
                        <button type="submit" class="btn btn-sm btn-primary" id="btnSubmit"><i class="fa fa-check"></i> 保 存</button>&nbsp;

                        <button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="closeView()"><i class="fa fa-times"></i> 关 闭</button>
                    </div>
                </div>
            </div>
            <div class="box-body">
                <div class="form-unit">基本信息</div>
                <input type="hidden" name="id" value="${maintainData.id}"/>
                <input type="hidden" name="createDate" value="${maintainData.createDate}"/>
                <input type="hidden" name="maintainTechnologyId" value="${maintainData.maintainTechnology.id}"/>
                <input type="hidden" name="timeStamp" value="${timeStamp}"/>
                <div class="row">
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required ">*</span> 维保项目：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <input path="name" name="name" value="${maintainData.name}" maxlength="100" class="form-control required ">
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required ">*</span> 维保类别：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <select class="form-control" name="category">
                                    <option <c:if test="${maintainData.category=='轻度保养'}">selected</c:if>>轻度保养</option>
                                    <option <c:if test="${maintainData.category=='中度保养'}">selected</c:if>>中度保养</option>
                                    <option <c:if test="${maintainData.category=='深度保养'}">selected</c:if>>深度保养</option>
                                </select>
                                <%--<input path="category" name="category" value="${maintainData.category}" maxlength="100" class="form-control required ">--%>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required ">*</span> 应用场景：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <input path="selectDictInfoId" id="selectDictInfoId" name="selectDictInfoId" class="form-control required">
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required ">*</span> 输入类型：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <select class="form-control" name="inputTypeEnum" onchange="changeType()" id="inputTypeEnum">
                                    <option value="TEXT" <c:if test="${maintainData.inputTypeEnum.code=='TEXT'}">selected</c:if>>文字</option>
                                    <option value="NUMBER" <c:if test="${maintainData.inputTypeEnum.code=='NUMBER'}">selected</c:if>>数字</option>
                                    <option value="IS_NORMAL" <c:if test="${maintainData.inputTypeEnum.code=='IS_NORMAL'}">selected</c:if>>正常与否</option>
                                    <option value="SWITCH" <c:if test="${maintainData.inputTypeEnum.code=='SWITCH'}">selected</c:if>>开关</option>
                                    <option value="STATUS_TYPE" <c:if test="${maintainData.inputTypeEnum.code=='STATUS_TYPE'}">selected</c:if>>良好、需处理（能运转）、需处理（不能运转）、处理后良好</option>
                                    <option value="COMPLETE_TYPE" <c:if test="${maintainData.inputTypeEnum.code=='COMPLETE_TYPE'}">selected</c:if>>完成正常、异常、未完成、无此项目</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                最大值：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <input path="maxNumber" name="maxNumber" id="maxNumber" value="${maintainData.maxNumber}" maxlength="100" class="form-control" type="number" readonly="readonly">
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                最小值：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <input path="minNumber" name="minNumber" id="minNumber" value="${maintainData.minNumber}" maxlength="100" class="form-control" type="number" readonly="readonly">
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                单位：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <input path="unit" name="unit" id="unit" value="${maintainData.unit}" maxlength="100" class="form-control" readonly="readonly">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                拍照：<i class="fa icon-question hide "></i></label>
                            <div class="col-sm-8">
                                <input type="checkbox" class="form-control" id="photo" name="photo"
                                       <c:if test="${maintainData.photo==true}">checked</c:if>
                                       style="margin-top: auto;margin-bottom: auto"/>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                上传资料(仅PDF)：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <div style="width: 300px;">
                                    <img class="startImg" id="img1" src="<c:url value="/resources/images/pdfUpLoad.png" />"
                                         onclick="$('#pic1').click();"/>
                                    <input type="file" style="display: none;" name="pic1" id="pic1" onchange="getimgload(1)"/>
                                    <label class="control-label col-sm-12" title="">
                                        <%--<a href="${filePath}" id="filePath" class="showFileName" target="_blank"></a>--%>
                                        <span class="showFileName"></span>
                                        <img class="deleteImg" id="delete1" src="<c:url value="/resources/images/delete.png"/>" onclick="delectImg(1)"/>
                                    </label>
                                    <input type="hidden" id="sImg1" name="sImg1" value="0"/><%--判断有没有变更图片用的 变了就为1 不变就为0--%>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row" id="contentRows">
                    <c:forEach items="${contentArray}" var="contentJson">
                        <div class="col-xs-12">
                            <div class="form-group">
                                <label class="control-label col-sm-2" title="">
                                    维保内容：<i class="fa icon-question hide"></i></label>
                                <div class="col-sm-9">
                                    <textarea name="array[]" rows="2" maxlength="500" class="form-control">${contentJson.text}</textarea>
                                </div>
                            </div>
                        </div>
                    </c:forEach>
                </div>
            </div>
            <div class="box-footer">
                <div class="row">
                    <div class="col-sm-offset-2 col-sm-12">
                        <button type="button" class="btn btn-sm btn-primary" id="btnAdd" onclick="addContent()"><i class="fa fa-check"></i> 增加维保内容</button>&nbsp;
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>
<script>
    $(function () {
        $('#photo').bootstrapSwitch({
            onText: "是",
            offText: "否",
            onColor: "success",
            offColor: "info"
        });

        var selectDictInfoId = $('#selectDictInfoId').magicSuggest({
            allowFreeEntries: false,
            data: '<c:url value="/web/admin/dictInfo/getDictInfoListMagic.action?typeCode=MAINTAIN_APPLICATION_SCENARIOS" />',
            queryParam: 'q',
            valueField: "value",
            displayField: "text",
            maxSelection: 1,
            noSuggestionText: '',
            placeholder: '请选择',
            required: true,
            autoSelect: true,
            selectFirst: true,
            value: magicSuggestValue('${maintainData.dictInfo.id}')
        });
    });


    $("#maintainDataForm").validate({
        submitHandler: function(form){
            js.ajaxSubmitForm($(form), function(data){
                js.showMessage(data.msg);
                if(data.status == Global.NO){
                    closeView();
                    parent.$("#maintainDataGrid").jqGrid().setGridParam({datatype:'json'}).trigger('reloadGrid');
                }
            }, "json");
        }
    });

    function closeView() {
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    }


    function delectImg(id) {
        $("#sImg" + id).val('1');
        $("#pic" + id).val('');
        $(".showFileName").html("");
        $("#img" + id).attr("src", "<c:url value="/resources/images/pdfUpLoad.png" />");
        $("#delete" + id).hide();
    }
    function getimgload(id) {
        var filePath=$('#pic1').val();
        var arr=filePath.split('\\');
        var fileName=arr[arr.length-1];

        var obj = document.getElementById("pic" + id);
        var stuff = obj.value.match(/^(.*)(\.)(.{1,8})$/)[3];
        if (stuff != 'pdf') {
            alert('只支持pdf文件');
            return false;
        }

        // $("#filePath").attr('href','');
        $(".showFileName").html(fileName);
        $("#sImg" + id).val('1');//表示图片变更了（总之不是原来的图片了）
        $("#delete" + id).show();
    }
    $(function () {
        if (${fileName != null && fileName != ''}) {
            $(".showFileName").html('${fileName}');
            $("#delete1").show();
        }
    });
</script>
<script>
    function addContent() {
        $("#contentRows").append('<div class="col-xs-12">\n' +
            '                            <div class="form-group">\n' +
            '                                <label class="control-label col-sm-2" title="">\n' +
            '                                    维保内容：<i class="fa icon-question hide"></i></label>\n' +
            '                                <div class="col-sm-9">\n' +
            '                                    <textarea name="array[]" rows="2" maxlength="500" class="form-control"></textarea>\n' +
            '                                </div>\n' +
            '                            </div>\n' +
            '                        </div>');

    }

    function changeType() {
        var inputTypeEnumCode = $("#inputTypeEnum").val();
        if(inputTypeEnumCode!='NUMBER'){
            document.getElementById("minNumber").readOnly=true;
            document.getElementById("maxNumber").readOnly=true;
            document.getElementById("unit").readOnly=true;
        }else{
            document.getElementById("minNumber").readOnly=false;
            document.getElementById("maxNumber").readOnly=false;
            document.getElementById("unit").readOnly=false;
        }
    }
    $(document).ready(function () {
        changeType();
    });
</script>


